import java.util.*;
import java.io.*;
import java.net.URI;
import java.nio.*;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.WatchEvent.Kind;
import java.nio.file.WatchEvent.Modifier;
public class TestWriteToFile {

	/**
	 * @param args
	 */
	public TestWriteToFile() {
	}
	public static long writeIo(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		long t1 = System.currentTimeMillis();
		for (int i=0;i<n;i++)
		{
			FileOutputStream outp = new FileOutputStream("tempio"+i+".txt");
			outp.write(buf);
			outp.flush();
			outp.close();
		}
		long t2 = System.currentTimeMillis();
		delIo(n);
		return (t2-t1)/n;
	}
	public long writeNio(int size,int n) throws IOException
	{
		byte[] buf = new byte[size];
		long t1 = System.currentTimeMillis();
		for (int i=0;i<n;i++)
		{
			Files.write(Paths.get("tempnio"+i+".txt"), buf);
		}
		long t2 = System.currentTimeMillis();
		delNio(n);
		return (t2-t1)/n;
	}
	
	private static void delIo(int n) throws IOException
	{
		for (int i =0;i<n;i++)
		{
		Files.delete(Paths.get("tempio"+i+".txt"));
		}
	}
	private static void delNio(int n) throws IOException
	{
		for (int i =0;i<n;i++)
		{
		Files.delete(Paths.get("tempnio"+i+".txt"));
		}
	}

}
